home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_019 / blackjack / outcom.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  64 lines

  1. /* outcom.c       print outcome of hand(s)
  2.  */
  3.  
  4. #include "local.h"
  5. #include "bj.h"
  6. #include "hndmgr.h"
  7.  
  8. static CASH value = {0};
  9.  
  10. /* outcom      - print outcome of hand and compute results
  11.  */
  12. CASH outcom(bet, tophand, isinsur, isdbl)
  13.    CASH  bet;           /* amount of player's bet */
  14.    short tophand;       /* how many player hands */
  15.    bool  isinsur;       /* player took insurance? */
  16.    bool  isdbl;         /* is player DBLDN? */
  17. {
  18.    void  prmsg();
  19.    bool  isbj();
  20.    short score();
  21.  
  22.    short h;             /* which hand */
  23.  
  24.    value = 0;
  25.    if (isinsur && isbj(DEALER))
  26.       prmsg(1, 1, "Insurance wins\n", ((bet) / (isdbl ? 4 : 2)));
  27.    else if (isinsur)
  28.       prmsg(1, 1, "Insurance loses\n", ((-bet) / (isdbl ? 4 : 2)));
  29.    if (isbj(DEALER) && !isbj(1))
  30.       prmsg(1, 1, "Dealer BJ beats all but BJ", ((-bet) / (isdbl ? 2 : 1)));
  31.    else if (isbj(DEALER) && isbj(1))
  32.       prmsg(1, 1, "Both BJ: push", (CASH)0);
  33.    else if (isbj(1))
  34.       prmsg(1, 1, "Your BJ wins 3 for 2", ((3 * bet) / 2));
  35.    else {
  36.       for (h = 1; h <= tophand; ++h) {
  37.          if (21 < score(h))
  38.             value -= bet;        /* "Bust" message already printed */
  39.          else if (score(DEALER) == score(h))
  40.             prmsg(h, tophand, "Push", (CASH)0);
  41.          else if (score(DEALER) < score(h) || 21 < score(DEALER))
  42.             prmsg(h, tophand, "Win", bet);
  43.          else
  44.             prmsg(h, tophand, "Lose", -bet);
  45.       }
  46.    }
  47.    return (value);
  48. }
  49.  
  50. /* prmsg    - prints appropriate message
  51.  */
  52. static void prmsg(h, tophand, s, delta)
  53.    short h;       /* which hand */
  54.    short tophand; /* how many hands */
  55.    char s[];      /* message */
  56.    CASH delta;    /* change of value ( + | - ) */
  57. {
  58.    if (tophand == 2)
  59.       printf("On hand %d, ", h);
  60.    printf("%s\n", s);
  61.    value += delta;
  62. }
  63.  
  64.